home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
cug172
/
lexsrt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-02-05
|
3KB
|
136 lines
/*
HEADER: CUG nnn.nn;
TITLE: LEX - A Lexical Analyser Generator
VERSION: 1.0 for IBM-PC
DATE: Jan 30, 1985
DESCRIPTION: A Lexical Analyser Generator. From UNIX
KEYWORDS: Lexical Analyser Generator YACC C PREP
SYSTEM: IBM-PC and Compatiables
FILENAME: LEXSRT.C
WARNINGS: This program is not for the casual user. It will
be useful primarily to expert developers.
CRC: N/A
SEE-ALSO: YACC and PREP
AUTHORS: Scott Guthery 11100 leafwood lane Austin, TX 78750
COMPILERS: DESMET-C
REFERENCES: UNIX Systems Manuals
*/
/*
* Quick Sort
*/
int (*qs__cmp)();
static int size;
qsort(a, n, es, fc)
char *a;
int n, es;
int (*fc)();
{
qs__cmp = fc;
size = es;
q_sort(a, a+n*es);
}
q_sort(a, l)
char *a, *l;
{
register char *i, *j;
register int es;
char *lp, *hp;
int n, c;
es = size;
start:
if((n=l-a) <= es)
return;
n = es * ( n/(2*es));
hp = lp = a+n;
i = a;
j = l-es;
for(;;) {
if(i < lp) {
if((c = (*qs__cmp)(i, lp)) == 0) {
q_exc(i, lp -= es);
continue;
}
if(c < 0) {
i += es;
continue;
}
}
loop:
if(j > hp) {
if((c = (*qs__cmp)(hp, j)) == 0) {
q_exc(hp += es, j);
goto loop;
}
if(c > 0) {
if(i == lp) {
q_tex(i, hp += es, j);
i = lp += es;
goto loop;
}
q_exc(i, j);
j -= es;
i += es;
continue;
}
j -= es;
goto loop;
}
if(i == lp) {
if(lp-a >= l-hp) {
q_sort(hp+es, l);
l = lp;
} else {
q_sort(a, lp);
a = hp+es;
}
goto start;
}
q_tex(j, lp -= es, i);
j = hp -= es;
}
}
q_exc(i, j)
char *i, *j;
{
register char *ri, *rj, c;
int n;
n = size;
ri = i;
rj = j;
do {
c = *ri;
*ri++ = *rj;
*rj++ = c;
} while(--n);
}
q_tex(i, j, k)
char *i, *j, *k;
{
register char *ri, *rj, *rk;
int c;
int n;
n = size;
ri = i;
rj = j;
rk = k;
do {
c = *ri;
*ri++ = *rk;
*rk++ = *rj;
*rj++ = c;
} while(--n);
}